#!/usr/bin/python
#coding:utf8
'''
Prototype
'''

import copy

class Prototype:
    def __init__(self):
        self._objects = {}

    def register_object(self, name, obj):
        """Register an object"""
        self._objects[name] = obj

    def unregister_object(self, name):
        """Unregister an object"""
        del self._objects[name]

    def clone(self, name, **attr):
        """Clone a registered object and update inner attributes dictionary"""
        obj = copy.deepcopy(self._objects.get(name))
        obj.__dict__.update(attr)
        return obj

class A:
    def __init__(self):
        self.a1 = 'a1'
        self.a2 = 'a2'
        print("A is created")

    def __str__(self):
        return "I am A"

class B:
    def __init__(self):
        self.b1 = 'b1'
        self.b2 = 'b2'
        print("B is created")

    def __str__(self):
        return "I am B"


if __name__ == '__main__':
    a = A()
    b = B()
    prototype = Prototype()
    prototype.register_object('a', a)
    prototype.register_object('b', b)
    a1 = prototype.clone('a', a=1, b=2, c=3)
    print(a1)
    print(a1.__dict__)
    